# myfile = open(r"ceshi.txt", "tr", encoding="utf-8")
# print(myfile.read())

# myfile1 = open(r"day07-while循环/ceshi.txt", mode="rt", encoding="utf-8")
# print(myfile1.read())
# myfile1.close


# # with的写法
# with open(r"day07-while循环\ceshi.txt", mode="rt", encoding="utf-8") as myfile02:
#     res = myfile02.read()
#     print(res)

# 在w模式打开文件没有关闭的情况下，连续下入，新的内容总是跟在旧的之后
# with open(r"66.txt", mode="wt", encoding="utf-8") as f:
#     f.write("6666\n你就是个傻逼\n\n")
#     f.write("6666\n你就是个傻逼\n\n")
#     f.write("6666\n你就是个傻逼\n\n")
#     f.write("6666\n你就是个傻逼\n\n")


# 操作模式

# r模式编写：
# with open('a.txt', mode='rt', encoding='utf-8') as f:
#     print('第一次读'.center(50, '+'))
#     print(f.read())
# 案例1
# username = 'lizi'
# passwrod = '123'

# with open('user.txt', mode='rt', encoding='utf-8') as f:
#     res = f.read()
#     username, passwrod = res.split('：')
# for inpe in range(1, 4):
#     inp_username = input('你的名字：').strip()
#     inp_password = input('你的密码：').strip()
#     if inp_username == username and inp_password == passwrod:
#         print('恭喜你登陆成功')
#         break
#     else:
#         if inpe == 3:
#             print("您的账号已经锁定！欢迎明天再试！谢谢！")
#         elif inpe <=3:
#             print('您已经登陆您的用户名或者密码有误！' + '\n您只有三次输入错误的机会，您已经错误：{}'.format(inpe) + '次')

# 案例2
# for inpe in range(1, 4):
#     inp_username = input("请输入您的用户名：").strip()
#     inp_password = input('请输入您的密码：').strip()
#     with open('user.txt', mode='rt', encoding='utf-8') as f:
#         for line in f:
#             username, password = line.strip().split(":")
#             if username == inp_username and password == inp_password:
#                 print("恭喜您登陆成功！")
#                 break
#         else:
#             if inpe == 4:
#                 print("您的账号已经锁定！欢迎明天再试！谢谢！")
#                 break
#             elif inpe <= 3:
#                 print('您已经登陆您的用户名或者密码有误！' + '\n您只有三次输入错误的机会，您已经错误：{}'.format(inpe) + '次')


# 2.w只写模式(直接清空覆盖)

# with open('b.txt', mode='wt', encoding='utf-8') as f:
#     f.write('66666\n7777\n999')
#
# # 2.a只写模式(追加模式)
# with open('b.txt', mode='at',encoding='utf-8') as  f:
#     f.write('\npppp')

# with open(r'maxresdefault (1).jpg', mo de='rb') as e:
#     print(e.read())

with open(r'user.txt', mode='wb') as f:
    f.write("你好".encode('gbk'))